#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
@author:shengwei
@file:collections_py.py
@time:2018/2/25 002515:44
"""
from collections import namedtuple, deque, defaultdict, OrderedDict, Counter
import base64
import struct
import hashlib
import hmac

point = namedtuple('point', ['x', 'y'])
p = point(1, 2)
# print(p.x, p.y,isinstance(p,tuple))
q = deque(['a', 'b', 'c'])
q.append('x')
q.appendleft('p')
# print(q)
dd = defaultdict(lambda: 'oop')
dd['stu'] = 'sw'
od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])
# print(dd['oop'], od, dict([('a', 1), ('b', 2), ('c', 3)]))
# 统计字符出现的个数
c = Counter()
for ch in 'programming':
    c[ch] = c[ch] + 1
# print(c)
# print(base64.b64encode(b'binary\x00string'),base64.b64decode(b'YmluYXJ5AHN0cmluZw=='))
# print(struct.pack('>I',2222))
enco = hashlib.sha1()
enco.update('this is a test'.encode('utf-8'))
# print(enco.hexdigest())
message = b'Hello, world!'
key = b'secret'
h = hmac.new(key,message,'MD5')
print(h.hexdigest())
